﻿function TrackingViewMarker(trackingView, map, infoWindow)
{
    var _trackingView = null;
    var _map = null;
    var _infoWindow = null;
    var _marker = null;
    this.getMarker = function () { return _marker; }
    this.setMarker = function (marker) { _marker = marker; }

    this.initialize = function ()
    {
        _trackingView = trackingView;
        _map = map;
        _infoWindow = infoWindow;
    }

    this.onClick = function ()
    {
        var dt = _trackingView.tracking_time;
        var strEval = "var dt = new Date" + dt.substring(dt.indexOf("("), dt.length - 1);
        eval(strEval);
        //var content = dt.getDate() + "/" + dt.getMonth() + "/" + dt.getFullYear() + " " + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds() + "<br>" + _marker.getPosition().lat() + ", " + _marker.getPosition().lng();
        var content = "<h5>" + _marker.getTitle() + "</h5>" +
            "Date/Time : " + dt.toUTCString() + "<br>" +
            "Latitude : " + _marker.getPosition().lat() + "<br>" +
            "Longitude : " + _marker.getPosition().lng();
        _infoWindow.setContent(content);
        _infoWindow.setPosition(_marker.getPosition());
        _infoWindow.open(_map, this);
    }

    this.initialize();
}

function TrackingViewDirections(fromTv, toTv, directionsRendererOptions)
{
    var _directionsRenderer = null;
    var _fromTv = null;
    var _toTv = null;

    var initialize = function ()
    {
        _fromTv = fromTv;
        _toTv = toTv;

        _directionsRenderer = new google.maps.DirectionsRenderer(directionsRendererOptions);
    }

    this.route = function (map, directionsService)
    {
        _directionsRenderer.setMap(map);

        directionsService.route
                (
                    {
                        origin: new google.maps.LatLng(_fromTv.latitude, _fromTv.longitude),
                        destination: new google.maps.LatLng(_toTv.latitude, _toTv.longitude),
                        travelMode: google.maps.TravelMode.WALKING
                    }, function (result, status)
                    {
                        if (status == google.maps.DirectionsStatus.OK)
                        {
                            _directionsRenderer.setDirections(result);
                        }
                    }
                );
    }

    initialize();
}